package GUIs;

import Configs.Config;
import Controllers.ChuNhaTroController;
import Controllers.MyTableFormat;
import Controllers.NguoiThueController;
import Controllers.NhanVienController_2;
import java.awt.event.KeyEvent;
import java.text.SimpleDateFormat;
import javax.swing.JOptionPane;
import models.NhanVien;
import java.awt.Image;
import javax.swing.ImageIcon;

public class f_nhanvien extends javax.swing.JFrame {

    private static f_nhanvien _instance;
    private final Config conn;
    private NhanVienController_2 tkcontrol;
    private NguoiThueController nguoithuecontrol;
    private ChuNhaTroController chunhatrocontrol;
    private NhanVien tkdangnhap;
    private final MyTableFormat myFormat;

    public f_nhanvien(Config conn) {
        this.conn = conn;
        initComponents();
        this.myFormat = new MyTableFormat();
        this.myFormat.formatTable(this.tbchunhatro);
        this.myFormat.formatTable(this.tbnguoithue);
        //
        ImageIcon icon = new ImageIcon(getClass().getResource("../img/house.png"));
        Image image = icon.getImage();
        setIconImage(image);
    }

    public static f_nhanvien getInstance(Config conn, String msnv) {
        if (_instance == null) {
            _instance = new f_nhanvien(conn);
        }
        if (msnv != null) {
            _instance.tkcontrol = new NhanVienController_2(_instance.conn);
            _instance.tkdangnhap = _instance.tkcontrol.getWithMSNV(msnv);
            _instance.reloadProfile();
            _instance.nguoithuecontrol = new NguoiThueController(_instance.conn);
            _instance.chunhatrocontrol = new ChuNhaTroController(_instance.conn);
        _instance.myFormat.clearTable(_instance.tbchunhatro);
        _instance.myFormat.clearTable(_instance.tbnguoithue);
            _instance.nguoithuecontrol.Show(_instance.tbnguoithue, null);
            _instance.chunhatrocontrol.Show(_instance.tbchunhatro, null);
        }
        return _instance;
    }

    public void createAndShowUI() {
        setVisible(true);
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        popcontrolchunhatro = new javax.swing.JPopupMenu();
        menuthemchunhatro = new javax.swing.JMenuItem();
        mensuattcbchunhatro = new javax.swing.JMenuItem();
        menuxoachunhatro = new javax.swing.JMenuItem();
        sepchunhatro = new javax.swing.JPopupMenu.Separator();
        menuxemdsnhatro = new javax.swing.JMenuItem();
        menuthemnhatro = new javax.swing.JMenuItem();
        popcontrolnguoithue = new javax.swing.JPopupMenu();
        menuthemnguoithue = new javax.swing.JMenuItem();
        menusuattcbnguoithue = new javax.swing.JMenuItem();
        menuxoanguoithue = new javax.swing.JMenuItem();
        sepnguoithue = new javax.swing.JPopupMenu.Separator();
        menuxemdshopdong = new javax.swing.JMenuItem();
        menuthemhopdong = new javax.swing.JMenuItem();
        tpchinh = new javax.swing.JTabbedPane();
        pnchunhatro = new javax.swing.JPanel();
        tftimchunhatro = new javax.swing.JTextField();
        btntimchunhatro = new javax.swing.JButton();
        sptbchunhatro = new javax.swing.JScrollPane();
        tbchunhatro = new javax.swing.JTable();
        btnrefreshchunhatro = new javax.swing.JButton();
        pnnguoithue = new javax.swing.JPanel();
        tftimnguoithue = new javax.swing.JTextField();
        btntimnguoithue = new javax.swing.JButton();
        sptbnguoithue = new javax.swing.JScrollPane();
        tbnguoithue = new javax.swing.JTable();
        btnrefreshnguoithue = new javax.swing.JButton();
        menu = new javax.swing.JMenuBar();
        menuchunhatro = new javax.swing.JMenu();
        menuitemthemchunhatro = new javax.swing.JMenuItem();
        mensuattcbchunhatro_top = new javax.swing.JMenuItem();
        menuxoachunhatro_top = new javax.swing.JMenuItem();
        sepchunhatro_top = new javax.swing.JPopupMenu.Separator();
        menuxemdsnhatro_top = new javax.swing.JMenuItem();
        menuthemnhatro_top = new javax.swing.JMenuItem();
        menunguoithue = new javax.swing.JMenu();
        menuitemthemnguoithue = new javax.swing.JMenuItem();
        menusuattcbnguoithue_top = new javax.swing.JMenuItem();
        menuxoanguoithue_top = new javax.swing.JMenuItem();
        sepnguoithue_top = new javax.swing.JPopupMenu.Separator();
        menuxemdshopdong_top = new javax.swing.JMenuItem();
        menuthemhopdong_top = new javax.swing.JMenuItem();
        menuhethong = new javax.swing.JMenu();
        menuthongtinuser = new javax.swing.JMenuItem();
        itemthongtin = new javax.swing.JMenuItem();
        itemdangxuat = new javax.swing.JMenuItem();
        itemthoat = new javax.swing.JMenuItem();
        menuttuser = new javax.swing.JMenu();

        menuthemchunhatro.setText("Thêm mới chủ nhà trọ");
        menuthemchunhatro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuthemchunhatroActionPerformed(evt);
            }
        });
        popcontrolchunhatro.add(menuthemchunhatro);

        mensuattcbchunhatro.setText("Sửa thông tin cơ bản chủ nhà trọ");
        mensuattcbchunhatro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mensuattcbchunhatroActionPerformed(evt);
            }
        });
        popcontrolchunhatro.add(mensuattcbchunhatro);

        menuxoachunhatro.setText("Xóa thông tin chủ nhà trọ");
        menuxoachunhatro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuxoachunhatroActionPerformed(evt);
            }
        });
        popcontrolchunhatro.add(menuxoachunhatro);
        popcontrolchunhatro.add(sepchunhatro);

        menuxemdsnhatro.setText("Xem các nhà trọ");
        menuxemdsnhatro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuxemdsnhatroActionPerformed(evt);
            }
        });
        popcontrolchunhatro.add(menuxemdsnhatro);

        menuthemnhatro.setText("Thêm nhà trọ");
        menuthemnhatro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuthemnhatroActionPerformed(evt);
            }
        });
        popcontrolchunhatro.add(menuthemnhatro);

        menuthemnguoithue.setText("Thêm mới người thuê");
        menuthemnguoithue.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuthemnguoithueActionPerformed(evt);
            }
        });
        popcontrolnguoithue.add(menuthemnguoithue);

        menusuattcbnguoithue.setText("Sửa thông tin cơ bản người thuê");
        menusuattcbnguoithue.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menusuattcbnguoithueActionPerformed(evt);
            }
        });
        popcontrolnguoithue.add(menusuattcbnguoithue);

        menuxoanguoithue.setText("Xóa thông tin người thuê");
        menuxoanguoithue.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuxoanguoithueActionPerformed(evt);
            }
        });
        popcontrolnguoithue.add(menuxoanguoithue);
        popcontrolnguoithue.add(sepnguoithue);

        menuxemdshopdong.setText("Xem các hợp đồng");
        menuxemdshopdong.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuxemdshopdongActionPerformed(evt);
            }
        });
        popcontrolnguoithue.add(menuxemdshopdong);

        menuthemhopdong.setText("Thêm hợp đồng");
        menuthemhopdong.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuthemhopdongActionPerformed(evt);
            }
        });
        popcontrolnguoithue.add(menuthemhopdong);

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Trang chủ quản lý chủ trọ và người thuê");
        setMinimumSize(new java.awt.Dimension(1024, 768));
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        tpchinh.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                tpchinhStateChanged(evt);
            }
        });

        tftimchunhatro.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                tftimchunhatroKeyPressed(evt);
            }
        });

        btntimchunhatro.setText("Tìm");
        btntimchunhatro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btntimchunhatroActionPerformed(evt);
            }
        });

        tbchunhatro.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "STT", "CMND", "Tên chủ nhà trọ", "Địa chỉ"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Integer.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tbchunhatro.setComponentPopupMenu(popcontrolchunhatro);
        tbchunhatro.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        tbchunhatro.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        tbchunhatro.getTableHeader().setReorderingAllowed(false);
        sptbchunhatro.setViewportView(tbchunhatro);
        if (tbchunhatro.getColumnModel().getColumnCount() > 0) {
            tbchunhatro.getColumnModel().getColumn(0).setResizable(false);
            tbchunhatro.getColumnModel().getColumn(1).setResizable(false);
            tbchunhatro.getColumnModel().getColumn(2).setResizable(false);
            tbchunhatro.getColumnModel().getColumn(3).setResizable(false);
        }

        btnrefreshchunhatro.setText("Làm mới");
        btnrefreshchunhatro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnrefreshchunhatroActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pnchunhatroLayout = new javax.swing.GroupLayout(pnchunhatro);
        pnchunhatro.setLayout(pnchunhatroLayout);
        pnchunhatroLayout.setHorizontalGroup(
            pnchunhatroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnchunhatroLayout.createSequentialGroup()
                .addComponent(tftimchunhatro, javax.swing.GroupLayout.PREFERRED_SIZE, 279, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btntimchunhatro)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnrefreshchunhatro)
                .addGap(0, 0, Short.MAX_VALUE))
            .addComponent(sptbchunhatro, javax.swing.GroupLayout.DEFAULT_SIZE, 995, Short.MAX_VALUE)
        );
        pnchunhatroLayout.setVerticalGroup(
            pnchunhatroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnchunhatroLayout.createSequentialGroup()
                .addGroup(pnchunhatroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tftimchunhatro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btntimchunhatro)
                    .addComponent(btnrefreshchunhatro))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(sptbchunhatro, javax.swing.GroupLayout.DEFAULT_SIZE, 654, Short.MAX_VALUE))
        );

        tpchinh.addTab("Chủ nhà trọ", pnchunhatro);

        tftimnguoithue.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                tftimnguoithueKeyPressed(evt);
            }
        });

        btntimnguoithue.setText("Tìm");
        btntimnguoithue.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btntimnguoithueActionPerformed(evt);
            }
        });

        tbnguoithue.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "STT", "CMND", "Họ tên", "Giới tính", "Mô tả công việc"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Integer.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tbnguoithue.setComponentPopupMenu(popcontrolnguoithue);
        tbnguoithue.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        tbnguoithue.getTableHeader().setReorderingAllowed(false);
        sptbnguoithue.setViewportView(tbnguoithue);
        if (tbnguoithue.getColumnModel().getColumnCount() > 0) {
            tbnguoithue.getColumnModel().getColumn(0).setResizable(false);
            tbnguoithue.getColumnModel().getColumn(1).setResizable(false);
            tbnguoithue.getColumnModel().getColumn(2).setResizable(false);
            tbnguoithue.getColumnModel().getColumn(3).setResizable(false);
            tbnguoithue.getColumnModel().getColumn(4).setResizable(false);
        }

        btnrefreshnguoithue.setText("Làm mới");
        btnrefreshnguoithue.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnrefreshnguoithueActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pnnguoithueLayout = new javax.swing.GroupLayout(pnnguoithue);
        pnnguoithue.setLayout(pnnguoithueLayout);
        pnnguoithueLayout.setHorizontalGroup(
            pnnguoithueLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnnguoithueLayout.createSequentialGroup()
                .addComponent(tftimnguoithue, javax.swing.GroupLayout.PREFERRED_SIZE, 279, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btntimnguoithue)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnrefreshnguoithue)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addComponent(sptbnguoithue, javax.swing.GroupLayout.DEFAULT_SIZE, 995, Short.MAX_VALUE)
        );
        pnnguoithueLayout.setVerticalGroup(
            pnnguoithueLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnnguoithueLayout.createSequentialGroup()
                .addGroup(pnnguoithueLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tftimnguoithue, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btntimnguoithue)
                    .addComponent(btnrefreshnguoithue))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(sptbnguoithue, javax.swing.GroupLayout.DEFAULT_SIZE, 654, Short.MAX_VALUE))
        );

        tpchinh.addTab("Người thuê", pnnguoithue);

        menuchunhatro.setText("Chủ nhà trọ");

        menuitemthemchunhatro.setText("Thêm mới chủ nhà trọ");
        menuitemthemchunhatro.setToolTipText("");
        menuitemthemchunhatro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuitemthemchunhatroActionPerformed(evt);
            }
        });
        menuchunhatro.add(menuitemthemchunhatro);

        mensuattcbchunhatro_top.setText("Sửa thông tin cơ bản chủ nhà trọ");
        mensuattcbchunhatro_top.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mensuattcbchunhatro_topActionPerformed(evt);
            }
        });
        menuchunhatro.add(mensuattcbchunhatro_top);

        menuxoachunhatro_top.setText("Xóa thông tin chủ nhà trọ");
        menuxoachunhatro_top.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuxoachunhatro_topActionPerformed(evt);
            }
        });
        menuchunhatro.add(menuxoachunhatro_top);
        menuchunhatro.add(sepchunhatro_top);

        menuxemdsnhatro_top.setText("Xem các nhà trọ");
        menuxemdsnhatro_top.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuxemdsnhatro_topActionPerformed(evt);
            }
        });
        menuchunhatro.add(menuxemdsnhatro_top);

        menuthemnhatro_top.setText("Thêm nhà trọ");
        menuthemnhatro_top.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuthemnhatro_topActionPerformed(evt);
            }
        });
        menuchunhatro.add(menuthemnhatro_top);

        menu.add(menuchunhatro);

        menunguoithue.setText("Người thuê");

        menuitemthemnguoithue.setText("Thêm người thuê");
        menuitemthemnguoithue.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuitemthemnguoithueActionPerformed(evt);
            }
        });
        menunguoithue.add(menuitemthemnguoithue);

        menusuattcbnguoithue_top.setText("Sửa thông tin cơ bản người thuê");
        menusuattcbnguoithue_top.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menusuattcbnguoithue_topActionPerformed(evt);
            }
        });
        menunguoithue.add(menusuattcbnguoithue_top);

        menuxoanguoithue_top.setText("Xóa thông tin người thuê");
        menuxoanguoithue_top.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuxoanguoithue_topActionPerformed(evt);
            }
        });
        menunguoithue.add(menuxoanguoithue_top);
        menunguoithue.add(sepnguoithue_top);

        menuxemdshopdong_top.setText("Xem các hợp đồng");
        menuxemdshopdong_top.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuxemdshopdong_topActionPerformed(evt);
            }
        });
        menunguoithue.add(menuxemdshopdong_top);

        menuthemhopdong_top.setText("Thêm hợp đồng");
        menuthemhopdong_top.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuthemhopdong_topActionPerformed(evt);
            }
        });
        menunguoithue.add(menuthemhopdong_top);

        menu.add(menunguoithue);

        menuhethong.setText("Hệ thống");

        menuthongtinuser.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_U, java.awt.event.InputEvent.ALT_MASK));
        menuthongtinuser.setText("Thông tin người dùng");
        menuthongtinuser.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuthongtinuserActionPerformed(evt);
            }
        });
        menuhethong.add(menuthongtinuser);

        itemthongtin.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_I, java.awt.event.InputEvent.ALT_MASK));
        itemthongtin.setText("Thông tin phần mềm");
        itemthongtin.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                itemthongtinActionPerformed(evt);
            }
        });
        menuhethong.add(itemthongtin);

        itemdangxuat.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F4, java.awt.event.InputEvent.ALT_MASK | java.awt.event.InputEvent.SHIFT_MASK));
        itemdangxuat.setText("Đăng xuất");
        itemdangxuat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                itemdangxuatActionPerformed(evt);
            }
        });
        menuhethong.add(itemdangxuat);

        itemthoat.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F4, java.awt.event.InputEvent.ALT_MASK));
        itemthoat.setText("Thoát chương trình");
        itemthoat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                itemthoatActionPerformed(evt);
            }
        });
        menuhethong.add(itemthoat);

        menu.add(menuhethong);

        menuttuser.setText("Thông tin người dùng");
        menuttuser.setFont(new java.awt.Font("Segoe UI", 1, 15)); // NOI18N
        menu.add(menuttuser);

        setJMenuBar(menu);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(tpchinh)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(tpchinh)
                .addContainerGap())
        );

        pack();
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents

    private void itemthongtinActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_itemthongtinActionPerformed
        JOptionPane.showMessageDialog(this, "Nhóm phát triển nhóm 7 cao học K21.\n Chuột Chết\nThánh Nhân\nVoi Con\nAn Lùn\nPhiên bản 0.1.", "Thông tin phần mềm", JOptionPane.INFORMATION_MESSAGE);
    }//GEN-LAST:event_itemthongtinActionPerformed

    private void itemdangxuatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_itemdangxuatActionPerformed
        f_dangnhap dangnhap = f_dangnhap.getInstance(this.conn);
        dangnhap.createAndShowUI();
        this.dispose();
    }//GEN-LAST:event_itemdangxuatActionPerformed

    private void itemthoatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_itemthoatActionPerformed
        this.conn.closeConn();
        this.dispose();
    }//GEN-LAST:event_itemthoatActionPerformed

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        this.conn.closeConn();
    }//GEN-LAST:event_formWindowClosing


    private void btnrefreshchunhatroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnrefreshchunhatroActionPerformed
        this.refreshChuNhaTro();
    }//GEN-LAST:event_btnrefreshchunhatroActionPerformed

    private void reloadProfile() {
        this.menuttuser.setText("Xin chào, (" + this.tkdangnhap.getMSNV() + ") " + this.tkdangnhap.getHoten());
    }

    public void refreshChuNhaTro() {
        this.tftimchunhatro.setText(null);
        this.myFormat.clearTable(this.tbchunhatro);
        this.chunhatrocontrol.Show(this.tbchunhatro, null);
    }

    public void refreshNguoiThue() {
        this.tftimnguoithue.setText(null);
        this.myFormat.clearTable(this.tbnguoithue);
        this.nguoithuecontrol.Show(this.tbnguoithue, null);
    }

    private void btnthemnguoithueActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnthemnguoithueActionPerformed
    }//GEN-LAST:event_btnthemnguoithueActionPerformed

    private void tftimnguoithueKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tftimnguoithueKeyPressed
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            this.searchNguoiThue();
        }
    }//GEN-LAST:event_tftimnguoithueKeyPressed

    private void btntimnguoithueActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btntimnguoithueActionPerformed
        this.searchNguoiThue();
    }//GEN-LAST:event_btntimnguoithueActionPerformed

    private void btnrefreshnguoithueActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnrefreshnguoithueActionPerformed
        this.refreshNguoiThue();
    }//GEN-LAST:event_btnrefreshnguoithueActionPerformed

    private void menuthemnguoithueActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuthemnguoithueActionPerformed
        f_nhanvien_nguoithue_them them_nguoithue = f_nhanvien_nguoithue_them.getInstance(this.conn);
        them_nguoithue.createAndShowUI();
    }//GEN-LAST:event_menuthemnguoithueActionPerformed

    private void menuxoanguoithueActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuxoanguoithueActionPerformed
        this.xoaNguoiThue();
    }//GEN-LAST:event_menuxoanguoithueActionPerformed

    private void menusuattcbnguoithueActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menusuattcbnguoithueActionPerformed
        this.suaNguoiThue();
    }//GEN-LAST:event_menusuattcbnguoithueActionPerformed

    private void menuxemdshopdongActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuxemdshopdongActionPerformed
        int row = this.tbnguoithue.getSelectedRow();
        if (row != -1) {
            String cmnd = this.tbnguoithue.getValueAt(row, 1).toString();
            f_nhanvien_nguoithue_qlhopdong nguoithue_dshopdong = f_nhanvien_nguoithue_qlhopdong.getInstance(this.conn, tkdangnhap.getMSNV(), cmnd);
            nguoithue_dshopdong.createAndShowUI();
            nguoithue_dshopdong.reloadForm();
        } else {
            JOptionPane.showMessageDialog(this, "Bạn chưa chọn đối tượng người thuê để xem danh sách hợp đồng!", "Thông báo", JOptionPane.WARNING_MESSAGE);
            this.tbnguoithue.requestFocus();
        }
    }//GEN-LAST:event_menuxemdshopdongActionPerformed

    private void menuthemhopdongActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuthemhopdongActionPerformed
        int row = this.tbnguoithue.getSelectedRow();
        if (row != -1) {
            String cmnd = this.tbnguoithue.getValueAt(row, 1).toString();
            f_nhanvien_nguoithue_hopdong_them hopdong_them = f_nhanvien_nguoithue_hopdong_them.getInstance(this.conn, this.tkdangnhap.getMSNV(), cmnd);
            hopdong_them.createAndShowUI();
        } else {
            JOptionPane.showMessageDialog(this, "Bạn chưa chọn đối tượng người thuê để thêm hợp đồng!", "Thông báo", JOptionPane.WARNING_MESSAGE);
            this.tbnguoithue.requestFocus();
        }
    }//GEN-LAST:event_menuthemhopdongActionPerformed

    private void menuthemchunhatroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuthemchunhatroActionPerformed
        f_nhanvien_chunhatro_them chunhatro_them = f_nhanvien_chunhatro_them.getInstance(this.conn);
        chunhatro_them.createAndShowUI();
    }//GEN-LAST:event_menuthemchunhatroActionPerformed

    private void mensuattcbchunhatroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mensuattcbchunhatroActionPerformed
        this.suaChuNhaTro();
    }//GEN-LAST:event_mensuattcbchunhatroActionPerformed

    private void menuxemdsnhatroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuxemdsnhatroActionPerformed
        int row = this.tbchunhatro.getSelectedRow();
        if (row != -1) {
            String cmnd = this.tbchunhatro.getValueAt(row, 1).toString();
            f_nhanvien_chunhatro_qlnhatro chunhatro_qlnhatro = f_nhanvien_chunhatro_qlnhatro.getInstance(this.conn, tkdangnhap.getMSNV(), cmnd);
            chunhatro_qlnhatro.refreshDsNhaTro();
            chunhatro_qlnhatro.createAndShowUI();
        } else {
            JOptionPane.showMessageDialog(this, "Bạn chưa chọn đối tượng chủ nhà trọ để xem!", "Thông báo", JOptionPane.WARNING_MESSAGE);
            this.tbchunhatro.requestFocus();
        }
    }//GEN-LAST:event_menuxemdsnhatroActionPerformed

    private void menuthemnhatroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuthemnhatroActionPerformed
        int row = this.tbchunhatro.getSelectedRow();
        if (row != -1) {
            String cmnd = this.tbchunhatro.getValueAt(row, 1).toString();
            f_nhanvien_chunhatro_nhatro_them nhatro_them = f_nhanvien_chunhatro_nhatro_them.getInstance(this.conn, tkdangnhap.getMSNV(), cmnd);
            nhatro_them.createAndShowUI();
        } else {
            JOptionPane.showMessageDialog(this, "Bạn chưa chọn đối tượng chủ nhà trọ để thêm nhà trọ!", "Thông báo", JOptionPane.WARNING_MESSAGE);
            this.tbchunhatro.requestFocus();
        }
    }//GEN-LAST:event_menuthemnhatroActionPerformed

    private void menuxoachunhatroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuxoachunhatroActionPerformed
        this.xoaChuNhaTro();
    }//GEN-LAST:event_menuxoachunhatroActionPerformed

    private void tftimchunhatroKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tftimchunhatroKeyPressed
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            this.searchChuNhaTro();
        }
    }//GEN-LAST:event_tftimchunhatroKeyPressed

    private void btntimchunhatroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btntimchunhatroActionPerformed
        this.searchChuNhaTro();
    }//GEN-LAST:event_btntimchunhatroActionPerformed

    private void tpchinhStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_tpchinhStateChanged
        int numTab = this.tpchinh.getSelectedIndex();
        if (numTab == 0) {
            this.menuchunhatro.setEnabled(true);
            this.menunguoithue.setEnabled(false);
        } else if (numTab == 1) {
            this.menuchunhatro.setEnabled(false);
            this.menunguoithue.setEnabled(true);
        }
    }//GEN-LAST:event_tpchinhStateChanged

    private void menuitemthemchunhatroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuitemthemchunhatroActionPerformed
        f_nhanvien_chunhatro_them chunhatro_them = f_nhanvien_chunhatro_them.getInstance(this.conn);
        chunhatro_them.createAndShowUI();
    }//GEN-LAST:event_menuitemthemchunhatroActionPerformed

    private void menuitemthemnguoithueActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuitemthemnguoithueActionPerformed
        f_nhanvien_nguoithue_them them_nguoithue = f_nhanvien_nguoithue_them.getInstance(this.conn);
        them_nguoithue.createAndShowUI();
    }//GEN-LAST:event_menuitemthemnguoithueActionPerformed

    private void menuthongtinuserActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuthongtinuserActionPerformed
        SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
        JOptionPane.showMessageDialog(this, "Thông tin tài khoản nhân viên:\n"
                + "\tMSNV: " + this.tkdangnhap.getMSNV() + "\n"
                + "\tHọ và tên: " + this.tkdangnhap.getHoten() + "\n"
                + "\tGiới tính: " + this.tkdangnhap.getGioitinh() + "\n"
                + "\tNgày sinh: " + sdf.format(this.tkdangnhap.getNgaysinh()) + "\n"
                + "\tSĐT: " + this.tkdangnhap.getSdt() + "\n", "Thông tin người dùng", JOptionPane.INFORMATION_MESSAGE);
    }//GEN-LAST:event_menuthongtinuserActionPerformed

    private void mensuattcbchunhatro_topActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mensuattcbchunhatro_topActionPerformed
        this.suaChuNhaTro();
    }//GEN-LAST:event_mensuattcbchunhatro_topActionPerformed

    private void menuxoachunhatro_topActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuxoachunhatro_topActionPerformed
        this.xoaChuNhaTro();
    }//GEN-LAST:event_menuxoachunhatro_topActionPerformed

    private void menuxemdsnhatro_topActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuxemdsnhatro_topActionPerformed
        int row = this.tbchunhatro.getSelectedRow();
        if (row != -1) {
            String cmnd = this.tbchunhatro.getValueAt(row, 1).toString();
            f_nhanvien_chunhatro_qlnhatro chunhatro_qlnhatro = f_nhanvien_chunhatro_qlnhatro.getInstance(this.conn, tkdangnhap.getMSNV(), cmnd);
            chunhatro_qlnhatro.refreshDsNhaTro();
            chunhatro_qlnhatro.createAndShowUI();
        } else {
            JOptionPane.showMessageDialog(this, "Bạn chưa chọn đối tượng chủ nhà trọ để xem!", "Thông báo", JOptionPane.WARNING_MESSAGE);
            this.tbchunhatro.requestFocus();
        }
    }//GEN-LAST:event_menuxemdsnhatro_topActionPerformed

    private void menuthemnhatro_topActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuthemnhatro_topActionPerformed
        int row = this.tbchunhatro.getSelectedRow();
        if (row != -1) {
            String cmnd = this.tbchunhatro.getValueAt(row, 1).toString();
            f_nhanvien_chunhatro_nhatro_them nhatro_them = f_nhanvien_chunhatro_nhatro_them.getInstance(this.conn, tkdangnhap.getMSNV(), cmnd);
            nhatro_them.createAndShowUI();
        } else {
            JOptionPane.showMessageDialog(this, "Bạn chưa chọn đối tượng chủ nhà trọ để thêm nhà trọ!", "Thông báo", JOptionPane.WARNING_MESSAGE);
            this.tbchunhatro.requestFocus();
        }
    }//GEN-LAST:event_menuthemnhatro_topActionPerformed

    private void menusuattcbnguoithue_topActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menusuattcbnguoithue_topActionPerformed
        this.suaNguoiThue();
    }//GEN-LAST:event_menusuattcbnguoithue_topActionPerformed

    private void menuxoanguoithue_topActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuxoanguoithue_topActionPerformed
        this.xoaNguoiThue();
    }//GEN-LAST:event_menuxoanguoithue_topActionPerformed

    private void menuxemdshopdong_topActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuxemdshopdong_topActionPerformed
        int row = this.tbnguoithue.getSelectedRow();
        if (row != -1) {
            String cmnd = this.tbnguoithue.getValueAt(row, 1).toString();
            f_nhanvien_nguoithue_qlhopdong nguoithue_dshopdong = f_nhanvien_nguoithue_qlhopdong.getInstance(this.conn, tkdangnhap.getMSNV(), cmnd);
            nguoithue_dshopdong.createAndShowUI();
            nguoithue_dshopdong.reloadForm();
        } else {
            JOptionPane.showMessageDialog(this, "Bạn chưa chọn đối tượng người thuê để xem danh sách hợp đồng!", "Thông báo", JOptionPane.WARNING_MESSAGE);
            this.tbnguoithue.requestFocus();
        }
    }//GEN-LAST:event_menuxemdshopdong_topActionPerformed

    private void menuthemhopdong_topActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuthemhopdong_topActionPerformed
        int row = this.tbnguoithue.getSelectedRow();
        if (row != -1) {
            String cmnd = this.tbnguoithue.getValueAt(row, 1).toString();
            f_nhanvien_nguoithue_hopdong_them hopdong_them = f_nhanvien_nguoithue_hopdong_them.getInstance(this.conn, this.tkdangnhap.getMSNV(), cmnd);
            hopdong_them.createAndShowUI();
        } else {
            JOptionPane.showMessageDialog(this, "Bạn chưa chọn đối tượng người thuê để thêm hợp đồng!", "Thông báo", JOptionPane.WARNING_MESSAGE);
            this.tbnguoithue.requestFocus();
        }
    }//GEN-LAST:event_menuthemhopdong_topActionPerformed

    private void searchChuNhaTro() {
        String txtsearh = tftimchunhatro.getText().trim();
        if (!txtsearh.isEmpty()) {
            this.myFormat.clearTable(this.tbchunhatro);
            this.chunhatrocontrol.Show(this.tbchunhatro, txtsearh);
        } else {
            JOptionPane.showMessageDialog(this, "Vui lòng nhập thông tin chủ nhà trọ tìm kiếm!", "Thông báo", JOptionPane.INFORMATION_MESSAGE);
            this.tftimchunhatro.requestFocus();
        }
    }

    private void searchNguoiThue() {
        String txtsearh = tftimnguoithue.getText().trim();
        if (!txtsearh.isEmpty()) {
            this.myFormat.clearTable(this.tbnguoithue);
            this.nguoithuecontrol.Show(this.tbnguoithue, txtsearh);
        } else {
            JOptionPane.showMessageDialog(this, "Vui lòng nhập thông tin người thuê tìm kiếm!", "Thông báo", JOptionPane.INFORMATION_MESSAGE);
            this.tftimnguoithue.requestFocus();
        }
    }

    private void xoaNguoiThue() {
        int row = this.tbnguoithue.getSelectedRow();
        if (row != -1) {
            if (JOptionPane.showConfirmDialog(this, "Xác nhận xóa nhân viên này?", "Xác nhận", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
                String cmnd = this.tbnguoithue.getValueAt(row, 1).toString();
                this.nguoithuecontrol.Delete(cmnd);
                this.refreshNguoiThue();
            }
        } else {
            JOptionPane.showMessageDialog(this, "Bạn chưa chọn đối tượng người thuê để xóa!", "Thông báo", JOptionPane.WARNING_MESSAGE);
            tbnguoithue.requestFocus();
        }
    }

    private void suaNguoiThue() {
        int row = this.tbnguoithue.getSelectedRow();
        if (row != -1) {
            String cmnd = this.tbnguoithue.getValueAt(row, 1).toString();
            f_nhanvien_nguoithue_sua sua_nguoithue = f_nhanvien_nguoithue_sua.getInstance(this.conn, cmnd);
            sua_nguoithue.createAndShowUI();
        } else {
            JOptionPane.showMessageDialog(this, "Bạn chưa chọn đối tượng người thuê để sửa!", "Thông báo", JOptionPane.WARNING_MESSAGE);
            this.tbnguoithue.requestFocus();
        }
    }

    private void suaChuNhaTro() {
        int row = this.tbchunhatro.getSelectedRow();
        if (row != -1) {
            String cmnd = this.tbchunhatro.getValueAt(row, 1).toString();
            f_nhanvien_chunhatro_sua chunhatro_sua = f_nhanvien_chunhatro_sua.getInstance(this.conn, cmnd);
            chunhatro_sua.createAndShowUI();
        } else {
            JOptionPane.showMessageDialog(this, "Bạn chưa chọn đối tượng chủ nhà trọ để sửa!", "Thông báo", JOptionPane.WARNING_MESSAGE);
            this.tbchunhatro.requestFocus();
        }
    }

    private void xoaChuNhaTro() {
        int row = this.tbchunhatro.getSelectedRow();
        if (row != -1) {
            if (JOptionPane.showConfirmDialog(this, "Xác nhận xóa chủ nhà trọ này?", "Xác nhận", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
                String cmnd = this.tbchunhatro.getValueAt(row, 1).toString();
                this.chunhatrocontrol.Delete(cmnd);
                this.refreshChuNhaTro();
            }
        } else {
            JOptionPane.showMessageDialog(this, "Bạn chưa chọn đối tượng chủ nhà trọ để xóa!", "Thông báo", JOptionPane.WARNING_MESSAGE);
            this.tbchunhatro.requestFocus();
        }
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnrefreshchunhatro;
    private javax.swing.JButton btnrefreshnguoithue;
    private javax.swing.JButton btntimchunhatro;
    private javax.swing.JButton btntimnguoithue;
    private javax.swing.JMenuItem itemdangxuat;
    private javax.swing.JMenuItem itemthoat;
    private javax.swing.JMenuItem itemthongtin;
    private javax.swing.JMenuItem mensuattcbchunhatro;
    private javax.swing.JMenuItem mensuattcbchunhatro_top;
    private javax.swing.JMenuBar menu;
    private javax.swing.JMenu menuchunhatro;
    private javax.swing.JMenu menuhethong;
    private javax.swing.JMenuItem menuitemthemchunhatro;
    private javax.swing.JMenuItem menuitemthemnguoithue;
    private javax.swing.JMenu menunguoithue;
    private javax.swing.JMenuItem menusuattcbnguoithue;
    private javax.swing.JMenuItem menusuattcbnguoithue_top;
    private javax.swing.JMenuItem menuthemchunhatro;
    private javax.swing.JMenuItem menuthemhopdong;
    private javax.swing.JMenuItem menuthemhopdong_top;
    private javax.swing.JMenuItem menuthemnguoithue;
    private javax.swing.JMenuItem menuthemnhatro;
    private javax.swing.JMenuItem menuthemnhatro_top;
    private javax.swing.JMenuItem menuthongtinuser;
    private javax.swing.JMenu menuttuser;
    private javax.swing.JMenuItem menuxemdshopdong;
    private javax.swing.JMenuItem menuxemdshopdong_top;
    private javax.swing.JMenuItem menuxemdsnhatro;
    private javax.swing.JMenuItem menuxemdsnhatro_top;
    private javax.swing.JMenuItem menuxoachunhatro;
    private javax.swing.JMenuItem menuxoachunhatro_top;
    private javax.swing.JMenuItem menuxoanguoithue;
    private javax.swing.JMenuItem menuxoanguoithue_top;
    private javax.swing.JPanel pnchunhatro;
    private javax.swing.JPanel pnnguoithue;
    private javax.swing.JPopupMenu popcontrolchunhatro;
    private javax.swing.JPopupMenu popcontrolnguoithue;
    private javax.swing.JPopupMenu.Separator sepchunhatro;
    private javax.swing.JPopupMenu.Separator sepchunhatro_top;
    private javax.swing.JPopupMenu.Separator sepnguoithue;
    private javax.swing.JPopupMenu.Separator sepnguoithue_top;
    private javax.swing.JScrollPane sptbchunhatro;
    private javax.swing.JScrollPane sptbnguoithue;
    private javax.swing.JTable tbchunhatro;
    private javax.swing.JTable tbnguoithue;
    private javax.swing.JTextField tftimchunhatro;
    private javax.swing.JTextField tftimnguoithue;
    private javax.swing.JTabbedPane tpchinh;
    // End of variables declaration//GEN-END:variables
}
